<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../../admin.xsl" />
	<xsl:include href="../../cp/path.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/admin/system_types.css" type="text/css" media="all" />
		</head>
		<body>
			<xsl:call-template name="admin-header" />
			
			<div id="blocks">
				<div id="blocks_inner" />
			</div>
			
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<xsl:param name="cnt" select="count(object[@type='explay_field'])" />
		<xsl:param name="oType" select="document(concat('xobject://explay_type/', @type-id))/data/object" />
		
		<div id="path">
			<xsl:apply-templates select="document('xmodule://cp/getPath/0;system;types')/data/response" mode="cp-path">
				<xsl:with-param name="activeLink">1</xsl:with-param>
			</xsl:apply-templates>
		</div>
		
		<h1>
			<xsl:text>Тип «</xsl:text>
			<xsl:value-of select="$oType/property[@name='title']/value" />
			<xsl:text>» ― поля</xsl:text>
		</h1>
		
		<xsl:apply-templates select="message" />
		
		<p><span class="add">Добавить поле:</span><xsl:text> </xsl:text><a href="{$baseURI}/admin/system/add_field/{@type-id}?type=scalar">скалярное</a>, <a href="{$baseURI}/admin/system/add_field/{@type-id}?type=tags">теги</a>, <a href="{$baseURI}/admin/system/add_field/{@type-id}?type=guide">справочник</a>, <a href="{$baseURI}/admin/system/add_field/{@type-id}?type=connected">связанное</a>, <a href="{$baseURI}/admin/system/add_field/{@type-id}?type=image">изображение</a>.</p>
		
		<xsl:if test="$cnt = 0">
			<p>Ни одного поля не создано</p>
		</xsl:if>
		<xsl:if test="$cnt != 0">
			<form action="{$baseURI}/admin/system/fields/{@type-id}" method="post">
				<table class="standart" cellspacing="0" cellpadding="0">
					<tbody>
						<tr>
							<th />
							<th>Название</th>
							<th>Алиас</th>
							<th>Тип</th>
							<th>Позиция</th>
							<th>Опции</th>
						</tr>
						
						<xsl:apply-templates select="object[@type='explay_field']" />
					</tbody>
				</table>
				
				<p>
					<input type="submit" name="save_position" value="Сохранить позиции полей" />
				</p>
			</form>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="object[@type='explay_field']">
		<tr>
			<td>
				<xsl:if test="property[@name='editable']/value = 1">
					<img src="{$baseURI}/images/admin/field-status-editable.png" title="Редактируемое" />
				</xsl:if>
				<xsl:if test="property[@name='required']/value = 1">
					<img src="{$baseURI}/images/admin/field-status-required.png" title="Обязательное" />
				</xsl:if>
				<xsl:if test="property[@name='allow_search']/value = 1">
					<img src="{$baseURI}/images/admin/field-status-allo_search.png" title="Разрешен поиск" />
				</xsl:if>
			</td>
			<td>
				<a href="{$baseURI}/admin/system/edit_field/{@id}" class="mainlink" title="Редактировать">
					<xsl:value-of select="property[@name='title']/value" />
				</a>
			</td>
			<td>
				<xsl:value-of select="property[@name='field_name']/value" />
			</td>
			<td>
				<xsl:call-template name="switch-character">
					<xsl:with-param name="value" select="property[@name='character']/value" />
				</xsl:call-template>
			</td>
			<td>
				<input type="text" name="field[{@id}]" class="field_position" autocomplete="off">
					<xsl:attribute name="value">
						<xsl:value-of select="property[@name='position']/value" />
					</xsl:attribute>
				</input>
			</td>
			<td>
				<xsl:if test="property[@name='locked']/value = '0'">
					<a href="{$baseURI}/admin/system/delete_field/{@id}?scode={$scode}" onclick="if(!confirm('Вы действительно хотите удалить поле? Данные всех объектов по этому полю будут утеряны безвозвратно.'))return false;">удалить</a>
				</xsl:if>
			</td>
		</tr>
	</xsl:template>
	
	<xsl:template name="switch-character">
		<xsl:param name="value" />
		
		<xsl:choose>
			<xsl:when test="$value = 'integer'">
				<xsl:text>Целое число</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'float'">
				<xsl:text>Дробное число</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'guide'">
				<xsl:text>Справочник</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'multiguide'">
				<xsl:text>Мульти-справочник</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'tags'">
				<xsl:text>Теги</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'boolean'">
				<xsl:text>Флажок</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'header'">
				<xsl:text>Заголовок</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'text'">
				<xsl:text>Текст</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'email'">
				<xsl:text>E-mail</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'date'">
				<xsl:text>Дата</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'birthdate'">
				<xsl:text>Число (дата)</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'latin'">
				<xsl:text>Латиница</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'image'">
				<xsl:text>Изображение</xsl:text>
			</xsl:when>
			<xsl:when test="$value = 'object_value'">
				<xsl:text>Связанное значение</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$value" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
</xsl:stylesheet>